package test.singleton;

public class ConCurrentLazy1 {
    private static ConCurrentLazy1 singleton;

    private ConCurrentLazy1() {
    }
    /*public synchronized static ConCurrentLazy1 getInstance() throws InterruptedException {
        // 模拟操作中的停顿
         Thread.sleep(10L);
        if(singleton == null) {
            singleton = new ConCurrentLazy1();
        }
        return singleton;
    }*/

    public static ConCurrentLazy1 getInstance() throws InterruptedException {
        // 模拟操作中的停顿
        synchronized (ConCurrentLazy1.class) {
            Thread.sleep(10L);
            if (singleton == null) {
                singleton = new ConCurrentLazy1();
            }
            return singleton;
        }
    }

}
